pro plotlidarprofiles, files, output_filename= output_filename, range = range, use_log = use_log, title = title, elev_angle = elev_angle, max_points = max_points

	; dealing with args
    if(n_elements(files) eq 0) then files = dialog_pickfile(filter='*.txt',/multiple_files);
    if(n_elements(output_filename) eq 0) then output_filename = 'idl.ps'
    if(n_elements(range) eq 0) then range = [0.0, 1.0]
	if(n_elements(title) eq 0) then title = ''
	if(n_elements(elev_angle) eq 0) then elev_angle = 90.0

	; read the data
    data = readlidartxt(files);

	; dealing with max_points
	if(n_elements(max_points) eq 1) then begin
		if( data.line_size gt max_points ) then begin
			data.line_size = max_points
			data.data = data.data[*, 0:max_points-1]
		endif
	endif
	line_size = data.line_size;

	; get data logged
	if(n_elements(use_log) ne 0) then begin
		data.data = alog10(data.data);
	endif 
	; try automaticly decide range, but works badly
	if(n_elements(range) eq 0) then begin
		if Keyword_Set(use_log) then begin
			range = [max(data.data) - 4, max(data.data)]
		endif else begin
			range = [min(data.data), max(data.data)]
		endelse
	endif

	pos_of_dot_ps = strpos(output_filename, '.ps', strlen(output_filename)-3);
	if(pos_of_dot_ps  ne -1) then begin
		output_filename_header = strmid(output_filename, 0, strlen(output_filename)-3);
	endif else begin
		output_filename_header = output_filename;
	endelse

	height_array = findgen(data.line_size)*data.binsize*sin(!pi*elev_angle/180.0)

	for i = 0,n_elements(data.julian)-1 do begin
		output_filename_final = output_filename_header + string(i, format='(%"%06d")') + '.ps'
		; get ps ready
		ps_start, filename=output_filename_final,/inches, xsize=4, ysize=10
		black=fsc_color('black', !D.table_size - 1);
		gray =fsc_color('gray',  !D.table_size - 2);
    
		position = [0.1, 0.15, 0.9, 0.9]
    

		; get image scaled and plotted

		plot,  data.data[i,*], height_array, $
			xrange=range, yrange=[min(height_array), max(height_array)], $
			position=position, xstyle=1, ystyle=1, $
			charsize = 1.0 , title = title, ytitle = 'km', $
			xticklen=-0.02, yticklen = -0.01, $ 
			color = black, psym=3
		plots, [0,0], [min(height_array), max(height_array)], color=gray
      
		ps_end, /png, /allow_transparent
    
	endfor
    
end
